package cn.com.taiji;

import com.jfinal.kit.StrKit;

import cn.com.taiji.controller.ControllerTemplate;
import cn.com.taiji.controller.ManagerImplTemplate;
import cn.com.taiji.controller.ManagerTemplate;
import cn.com.taiji.core.CommonRun;
import cn.com.taiji.entity.EntityGenTemplate;
import cn.com.taiji.entity.PageRequestGenTemplate;
import cn.com.taiji.front.JspsGenTemplate;
import cn.com.taiji.jparepo.RepoGenTemplate;

/**
 * 
 * @author dongwei dongweia@mail.taiji.com.cn
 *
 */
public class RunCodegen extends CommonRun {

	public static void main(String targetProject, String basePackage, String[] tableNames) {

		// 1 entity所在包目录
		String modelPackage = basePackage + ".entity";
		// 文件后缀
		String suffix = "";
		doGenerate(tableNames, suffix, new EntityGenTemplate(modelPackage, targetProject, suffix));

		// 2 PageRequest所在包目录
		modelPackage = basePackage + ".repo.request.acl";
		suffix = "PageRequest";
		doGenerate(tableNames, suffix, new PageRequestGenTemplate(modelPackage, targetProject, suffix));

		// 3 Repo所在包目录
		modelPackage = basePackage + ".repo.jpa";
		suffix = "Repo";
		doGenerate(tableNames, suffix, new RepoGenTemplate(modelPackage, targetProject, suffix));

		// 4 Controller所在包目录
		modelPackage = basePackage + ".web.acl";
		suffix = "Controller";
		doGenerate(tableNames, suffix, new ControllerTemplate(modelPackage, targetProject, suffix));

		// 5 Manager所在包目录
		modelPackage = basePackage + ".manager.acl";
		suffix = "Manager";
		doGenerate(tableNames, suffix, new ManagerTemplate(modelPackage, targetProject, suffix));

		// 6 ManagerImpl所在包目录
		modelPackage = basePackage + ".manager.acl";
		suffix = "ManagerImpl";
		doGenerate(tableNames, suffix, new ManagerImplTemplate(modelPackage, targetProject, suffix));

		// 7 前端通用代码生成
		for (String tableName : tableNames) {
			String modelName = StrKit.toCamelCase(tableName);
			modelPackage = "war.WEB-INF.jsp.acl." + modelName;
			suffix = "jsp";
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "add"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "edit"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "info"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "manage"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "queryResult"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "result"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "row"));
			doGenerate(tableNames, suffix, new JspsGenTemplate(modelPackage, targetProject, suffix, "view"));
		}
	}
}
